package org.shj.tokenizer;

import com.hankcs.hanlp.classification.tokenizers.ITokenizer;
import com.hankcs.hanlp.model.perceptron.PerceptronLexicalAnalyzer;
import com.hankcs.hanlp.tokenizer.lexical.AbstractLexicalAnalyzer;

import java.io.IOException;
import java.util.List;

/**
 * @author Shen Huang Jian
 * @date 2020-10-01 9:19
 */
public class CustomerNLPTokenizer implements ITokenizer {

    /**
     * 预置分词器
     */
    public static AbstractLexicalAnalyzer ANALYZER;

    static
    {
        try
        {
            // 目前感知机的效果相当不错，如果能在更大的语料库上训练就更好了
            ANALYZER = new PerceptronLexicalAnalyzer();
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String[] segment(String text){
        List<String> texts = ANALYZER.segment(text);
        String[] results = new String[texts.size()];
        for(int i = 0 ; i < texts.size(); i++){
            results[i] = texts.get(i);
        }
        return results;
    }


}
